#ifndef __OPENGLES_PIPE__
#define __OPENGLES_PIPE__

#include "pipeconn.h"
#include "virtio_common.h"
#include "VBoxDD.h"

#define GLES_PCI_SUBSYSTEM_ID 20 //according to kernel VIRTIO_ID_  define
#define GLES_PCI_CLASS 0xff
#define GLES_N_QUEUES 3
#define GLES_NAME_FMT "VirtIO_GLES%d"
#define PIPE_NAME_FORMAT "\\\\.\\pipe\\%s_gles"

//#define _DEBUG_
#ifdef _DEBUG_
#define TRACE(format, ...)                                                                                            \
	{                                                                                                                 \
		char buffer[256] = {0};                                                                                       \
		SYSTEMTIME ct;                                                                                                \
		GetLocalTime(&ct);                                                                                            \
		sprintf(buffer, "%d:%d:%d.%d:   " format, ct.wHour, ct.wMinute, ct.wSecond, ct.wMilliseconds, ##__VA_ARGS__); \
		OutputDebugStringA(buffer);                                                                                   \
	}
#else
#define TRACE(format, ...)
#endif


typedef struct esState
{
	/* VPCISTATE must be the first member! */
	VPCISTATE VPCI;
	R3PTRTYPE(PVQUEUE) pRxQueue;
	R3PTRTYPE(PVQUEUE) pTxQueue;
	R3PTRTYPE(PVQUEUE) pCtlQueue;
	PPDMINETWORKUP pDrv;
	RTTHREAD WriteThread;
	RTSEMEVENT EventWrite;
	int WriteLoop;
} OpenglesState;

struct channel_pipe
{	
	HANDLE pipe;
	int64_t channel;
	OVERLAPPED ol_read;
	OVERLAPPED ol_write;
	unsigned char *readbuffer;
	OpenglesState *dev;
	VQUEUEELEM *elem;
	RTTHREAD ReadThread;
	RTSEMEVENT ChannelRead;
};

static DECLCALLBACK(int) PipeReadThread(RTTHREAD ThreadSelf, void *pvUser);

#endif